﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace tema_pattern
{
    class CarPool:ReprezentantaAuto
    {
        static CarPool _instance;
        public List<Masina> lista;


        private CarPool() //lista de masini existente  -- Object Pool
        {
            lista = new List<Masina>();

            lista.Add(new Coupe("Ferrari", "rosu", "auto", "benzina", "2m", "fibra carbon"));
            lista.Add(new Coupe("Porsche", "rosu", "auto", "benzina", "1.8m", "piele nappa"));
            lista.Add(new Coupe("BMW", "rosu", "auto", "benzina", "2.4m", "xdrive"));

            lista.Add(new Mini("Mini", "bleu", " manuala", "benzina", "1.3m", "navigatie"));
            lista.Add(new Mini("Smart", "bleu", " manuala", "benzina", "1m", "panoramic"));
            lista.Add(new Mini("Opel", "bleu", " manuala", "benzina", "1.1m", "clima"));

            lista.Add(new Sedan("Audi", "negru", "auto", "diesel", "4m", "minibar"));
            lista.Add(new Sedan("VW", "negru", "auto", "diesel", "3.6m", "voice control"));
            lista.Add(new Sedan("Maybach", "negru", "auto", "diesel", "6.2m", "full options"));

        }

        public static CarPool Instance() // singleton pattern
        {
            if (_instance == null)
                _instance = new CarPool();

            return _instance;
        }


        public override void put(Masina m)
        {
            lista.Add(m);
        }

        public override Masina get(string x) // cauta in showroom marca care o introduce clientul de la tst
        {
            Masina car = new Sedan();
            foreach (Masina m in lista)
                if (m.get_marca().ToLower() == x.ToLower()) 
                    return m;
            return car;
        }

        public override void sterge(Masina m)
        {
            lista.Remove(m);
        }
        public override void print()
        {
            foreach (Masina m in lista)
                Console.WriteLine(m.get_marca());
           
        }
    }
}
